aPLib - Decompression

Decompression

The following is a description of the aPLib decompression functionality.

#### Decompression Functions

    size_t aP_depack( const void *source,
                      void *destination );

Decompresses the compressed data from `source[]` into `destination[]`.

The `destination[]` buffer must be large enough to hold the decompressed data.

Parameters:
  `source` - pointer to the compressed data.
  `destination` - pointer to where the decompressed data should be stored.
Returns:
  the length of the decompressed data, or `APLIB_ERROR` on error.
Note:
  This function is not included in the libraries, but is available in `src/c/depack.c`. aP_depack_asm_fast can be used instead.

    size_t aP_depack_safe( const void *source,
                           size_t srclen,
                           void *destination,
                           size_t dstlen );

Decompresses the compressed data from `source[]` into `destination[]`.

This function reads at most `srclen` bytes from `source[]`, and writes at most `dstlen` bytes to `destination[]`. If there is not enough source or destination space, or a decoding error occurs, the function returns `APLIB_ERROR`.

Parameters:
  `source` - pointer to the compressed data.
  `srclen` - the size of the source buffer in bytes.
  `destination` - pointer to where the decompressed data should be stored.
  `dstlen` - the size of the destination buffer in bytes.
Returns:
  the length of the decompressed data, or `APLIB_ERROR` on error.
Note:
  This function is not included in the libraries, but is available in `src/c/depacks.c`. aP_depack_asm_safe can be used instead.

    size_t aP_depack_asm( const void *source,
                          void *destination );

Decompresses the compressed data from `source[]` into `destination[]`.

The `destination[]` buffer must be large enough to hold the decompressed data.

Optimised for size.

Parameters:
  `source` - pointer to the compressed data.
  `destination` - pointer to where the decompressed data should be stored.
Returns:
  the length of the decompressed data, or `APLIB_ERROR` on error.

    size_t aP_depack_asm_fast( const void *source,
                               void *destination );

Decompresses the compressed data from `source[]` into `destination[]`.

The `destination[]` buffer must be large enough to hold the decompressed data.

Optimised for speed.

Parameters:
  `source` - pointer to the compressed data.
  `destination` - pointer to where the decompressed data should be stored.
Returns:
  the length of the decompressed data, or `APLIB_ERROR` on error.

    size_t aP_depack_asm_safe( const void *source,
                               size_t srclen,
                               void *destination,
                               size_t dstlen );

Decompresses the compressed data from `source[]` into `destination[]`.

This function reads at most `srclen` bytes from `source[]`, and writes at most `dstlen` bytes to `destination[]`. If there is not enough source or destination space, or a decoding error occurs, the function returns `APLIB_ERROR`.

Parameters:
  `source` - pointer to the compressed data.
  `srclen` - the size of the source buffer in bytes.
  `destination` - pointer to where the decompressed data should be stored.
  `dstlen` - the size of the destination buffer in bytes.
Returns:
  the length of the decompressed data, or `APLIB_ERROR` on error.
See Also:
  `aPsafe_depack`

    unsigned int aP_crc32( const void *source,
                           size_t length );

Computes the CRC32 value of `length` bytes of data from `source[]`.

Parameters:
  `source` - pointer to the data to process.
  `length` - the size in bytes of the data.
Returns:
  the CRC32 value.

#### Safe Wrapper Functions

    size_t aPsafe_check( const void *source );

Computes the CRC32 of the compressed data in `source[]` and checks it agains the value in the header. Returns the length of the decompressed data stored in the header..

Parameters:
  `source` - the compressed data to process.
Returns:
  the length of the decompressed data, or `APLIB_ERROR` on error.

    size_t aPsafe_get_orig_size( const void *source );

Returns the length of the decompressed data stored in the header of the compressed data in `source[]`.

Parameters:
  `source` - the compressed data to process.
Returns:
  the length of the decompressed data, or `APLIB_ERROR` on error.

    size_t aPsafe_depack( const void *source,
                          size_t srclen,
                          void *destination,
                          size_t dstlen );

Wrapper function for `aP_depack_asm_safe`, which checks the CRC32 of the compressed data, decompresses, and checks the CRC32 of the decompressed data.

Parameters:
  `source` - pointer to the compressed data.
  `srclen` - the size of the source buffer in bytes.
  `destination` - pointer to where the decompressed data should be stored.
  `dstlen` - the size of the destination buffer in bytes.
Returns:
  the length of the decompressed data, or `APLIB_ERROR` on error.
See Also:
  `aP_depack_asm_safe`

#### Example

       /* get original size */
       size_t orig_size = aPsafe_get_orig_size(compressed);

       /* allocate memory for decompressed data */
       char *data = malloc(orig_size);

       /* decompress compressed[] to data[] */
       size_t outlength = aPsafe_depack(compressed, compressed_size, data, orig_size);

       /* check decompressed length */
       if (outlength != orig_size) {
          printf("An error occured!\n");
       }
       else {
          printf("Decompressed %u bytes\n", outlength);
       }

<< prev | home | next >>